package com.th.cash.th2.h5

import androidx.lifecycle.viewModelScope
import com.th.basemodel.base.BaseViewModel
import com.th.cash.th2.login.LoginRepository
import com.th.cash.th2.splash.SplashIntent
import com.th.cash.th2.splash.SplashRepository
import com.th.cash.th2.splash.SplashState
import kotlinx.coroutines.channels.Channel
import kotlinx.coroutines.flow.MutableStateFlow
import kotlinx.coroutines.flow.StateFlow
import kotlinx.coroutines.flow.consumeAsFlow
import kotlinx.coroutines.flow.debounce
import kotlinx.coroutines.launch
import javax.inject.Inject

class H5Vm : BaseViewModel() {

    private val repository by lazy{
        H5Repository()
    }

    val intentChannel = Channel<H5Intent>(Channel.UNLIMITED)

    //可变状态数据流（读写）（StateFlow替代LiveData，难道每一个页面都需要定义一个）
    private val _uiState = MutableStateFlow<H5State>(H5State.Idle)

    //可观察状态数据流（只读）
    val uiState: StateFlow<H5State> get() = _uiState

    init {
        viewModelScope.launch {
            intentChannel.consumeAsFlow().debounce(500).collect { value ->
                when (value) {
                    is H5Intent.Idle -> {

                    }
                    else ->{

                    }
                }
            }
        }
    }

}